package data_management;

import junit.framework.TestCase;

public class PermissionManagerTest extends TestCase {
	
	/*************************************************************************
	 * This method tests the inititalize() method of the PermissionManager Class
	 *************************************************************************/
	public void testinitialize(){
		
		InvDBManager.getInstance().initializeDatabase();
		new Main();
		
		PermissionManager.getInstance().initialize();
		
	}
	
	/*************************************************************************
	 * This method tests the loginUser() method of the PermissionManager Class
	 *************************************************************************/
	public void testloginUser(){
		
		InvDBManager.getInstance().initializeDatabase();
		new Main();
		
		//test logging in of a valid user
		PermissionManager.getInstance().loginUser("j", "j");
		assertTrue(PermissionManager.getInstance().desktopUser!=null);
		
		
		//test logging in of an invalid user
		PermissionManager.getInstance().loginUser("invalidusername", "definitelynotanyonespassword");
		assertTrue(PermissionManager.getInstance().desktopUser!=null);
		
		//test logging in with blank fields
		PermissionManager.getInstance().loginUser("", "");
		assertTrue(PermissionManager.getInstance().desktopUser!=null);

		
	}
	
	/*************************************************************************
	 * This method tests the loginUser() method of the PermissionManager Class
	 *************************************************************************/
	public void testhasPermission(){
		
		User adminuser = new User();
		adminuser.name = "adminuser";
		adminuser.status = UserStatus.ADMIN;
			
		User clerkuser = new User();
		clerkuser.name = "clerkuser";
		clerkuser.status = UserStatus.CLERK;
					
		//test the permissions for adding a category
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.ADD_CATEGORY, adminuser));
		assertTrue(!PermissionManager.getInstance().hasPermission(Activity.ADD_CATEGORY, clerkuser));
		
		//test the permissions for adding an entry
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.ADD_ENTRY, adminuser));
		assertTrue(!PermissionManager.getInstance().hasPermission(Activity.ADD_ENTRY, clerkuser));
		
		//test the permissions for modifying an entry
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.MODIFY_ENTRY, adminuser));
		assertTrue(!PermissionManager.getInstance().hasPermission(Activity.MODIFY_ENTRY, clerkuser));

		//test the permissions for doing a query
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.QUERY, adminuser));
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.QUERY, clerkuser));
		
		//test the permissions for removing a category
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.REMOVE_CATEGORY, adminuser));
		assertTrue(!PermissionManager.getInstance().hasPermission(Activity.REMOVE_CATEGORY, clerkuser));
		
		//test the permissions for remove entry
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.REMOVE_ENTRY, adminuser));
		assertTrue(!PermissionManager.getInstance().hasPermission(Activity.REMOVE_ENTRY, clerkuser));
		
		//test the permissions for doing a sale
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.SALE, adminuser));
		assertTrue(PermissionManager.getInstance().hasPermission(Activity.SALE, clerkuser));
				
	}
	
	

}
